package com.gitee.wsl.mathematics.vector.ext

import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.mathematics.vector.vec3.Vector3
import com.gitee.wsl.mathematics.vector.vec4.Vector4


/** Returns [Vector2] whose value is limited between [min] and [max] per vector component. */
fun<T:Number,V:Vector2<T,V>> Vector2<T, V>.clamp(min : Vector2<T, *>, max : Vector2<T, *>) =
    create(clamp(x,min.x, max.x),
           clamp(y,min.y, max.y))

fun<T:Number,V:Vector2<T,V>> Vector2<T, V>.clamp(min : T, max : T) =
    create(clamp(x,min, max),
           clamp(y,min, max))

/** Returns [Vector3] whose value is limited between [min] and [max] per vector component. */
fun<T:Number,V:Vector3<T,V>> Vector3<T, V>.clamp(min : Vector3<T, *>, max : Vector3<T, *>) =
    create(clamp(x,min.x, max.x),
           clamp(y,min.y, max.y),
           clamp(z,min.y, max.z))

fun<T:Number,V:Vector3<T,V>> Vector3<T, V>.clamp(min : T, max : T) =
    create(clamp(x,min, max),
           clamp(y,min, max),
           clamp(z,min, max))

/** Returns [Vector4] whose value is limited between [min] and [max] per vector component. */
fun<T:Number,V:Vector4<T,V>> Vector4<T, V>.clamp(min : Vector4<T, *>, max : Vector4<T, *>) =
    create(clamp(x,min.x, max.x),
            clamp(y,min.y, max.y),
            clamp(z,min.z, max.z),
            clamp(w,min.w, max.w))

fun<T:Number,V:Vector4<T,V>> Vector4<T, V>.clamp(min : T, max : T) =
    create(clamp(x,min, max),
           clamp(y,min, max),
           clamp(z,min, max),
           clamp(w,min, max))